<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
 * Asset Manager
 *
 * Software to automatically manage how assets are delivered on a website
 *
 * @package		Asset Manager
 * @author		Adam Lewis <adam.lewis@bestservedcold.com>
 * @copyright	Copyright (c) 2006 - 2012, Best Served Cold Media Limited.
 * @license		http://bestservedcold.com/license.html
 * @link		http://bestservedcold.com
 * @since		Version 1.0
 * @filesource
 */

// ------------------------------------------------------------------------

/**
 * MY_Ouput class
 *
 * Wasn't sure if this should be a hook or just to extend the Output class... This simply calls the parent _display
 * function after it's altered the output to search and replace the assets, as long as it's setup in the config.
 *
 * @package		Asset Manager
 * @subpackage	Assets
 * @category	Libraries
 * @author  	Adam Lewis <adam.lewis@bestservedcold.com>
 * @since		2012-05-22
 */

class MY_Output extends CI_Output {

	/**
	 * Construct
	 *
	 * Simply calls the parent constructer so we have all the methods we need
	 *
	 * @access	public
	 * @since	2012-06-09
	 * @return	void
	 */
	public function __construct()
	{
		log_message('debug', '[MY_Output] class loaded');
		parent::__construct();
	}

	/**
	 * (non-PHPdoc)
	 * @see CI_Output::_display()
	 */
	public function _display()
	{
		// Get our info and get started...
		$CI = get_instance();
		$output = $this->get_output();

		// Firstly, let's get asset manager involved to see if it needs to do anything...
		if ($CI->config->item('query', 'asset_manager') == 'single')
		{
			$CI->load->library('asset_manager/am_single_query/am_single_query_output');
			$output = $CI->am_single_query_output->process_output();
		}

		// bit of optimization if the config wants it
		if ($compress_output = $CI->config->item('minify_output', 'asset_manager'))
		{
			if ($compress_output == 'minify')
			{
				require_once(APPPATH.'libraries/minify/min/lib/Minify/HTML.php');
				$output = Minify_HTML::minify($output);
			}
			else
			{
				$CI->load->library('asset_manager/am_optimize/am_optimize_html');
				$output = $CI->am_optimize_html->output($output);
			}
		}

		// All done, set the output
		$this->set_output($output);
		// Let CodeIgniter do it's bits...
		parent::_display();
	}
}